﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Entity;
using BO;
namespace Final_Prototype_UsingDev_QuanLy_071012
{
    public partial class Form_Custom_Management : Form
    {
        CustomerBO csBO = new CustomerBO();
        public delegate void UpdateData();
        public delegate void delPassData(string sData);     
        
        public Form_Custom_Management()
        {
            InitializeComponent();

        }

        private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void ribbonControl1_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //Form_Custom_Management_Add fr2 = new Form_Custom_Management_Add(this);            
            //fr2.Show();
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {


        }

        private void Form_Custom_Management_Load(object sender, EventArgs e)
        {
           // LoadCustomer();
        }

        private void Form_Custom_Management_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you want to quit?", "Warning", MessageBoxButtons.YesNo);
            if (result != DialogResult.Yes)
                e.Cancel = true;
        }
        /// <summary>
        /// tim kiem khach hang
        /// </summary>
        private void FindCustomer()
        {
            grdCustomerInfo.DataSource = csBO.FindCustomer(txtFind.Text.ToString());
        }

        /// <summary>
        /// load danh sach khach hang
        /// </summary>
        public void LoadCustomer()
        {
            grdCustomerInfo.DataSource = csBO.LoadCustomer();
            for (int i = 9; i <= 15; i++)
                grdCustomerInfo.Columns[i].Visible = false;
        }

        /// <summary>
        /// Xoa khach hang
        /// </summary>
        private void DeleteCustomer()
        {
            DialogResult result = MessageBox.Show("Are you want to delete this customer?", "Warning", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in grdCustomerInfo.Rows)
                {
                    if (row.Selected == true)
                    {
                        int index = row.Index;
                        csBO.DeleteCustomer(grdCustomerInfo.Rows[index].Cells["CustomerCode"].Value.ToString());
                    }
                }
                LoadCustomer();
            }
        }

        private void btnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DeleteCustomer();
        }

        private void grdCustomerInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void grdCustomerInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            FindCustomer();
        }

       

        private void grdCustomerInfo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //Form_Custom_Management_Edit fr2 = new Form_Custom_Management_Edit(this);
            //string sFormName;
            //foreach (DataGridViewRow row in grdCustomerInfo.Rows)
            //{
            //    if (row.Selected == true)
            //    {
            //        int index = row.Index;
            //        sFormName = grdCustomerInfo.Rows[index].Cells["CustomerCode"].Value.ToString();
            //        fr2.Text = sFormName;
            //        delPassData del = new delPassData(fr2.FillInfo);
            //        del(sFormName);
            //    }
            //}
            //fr2.Show();
        }

        private void txtFin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnShowAllCustomer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LoadCustomer();
        }

        private void btnShowSaleCustomer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            grdCustomerInfo.DataSource= csBO.LoadCustomerBySaleName("S1 - LONG NGUYEN");
        }

        private void btnAuthorized_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Form fr1 = new Form_Custom_Authorized();
            fr1.Show();
        }

        private void barEditItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnShowAllCustomer_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LoadCustomer();
        }

        private void ShowSaleCustomer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            grdCustomerInfo.DataSource = csBO.LoadCustomerBySaleName("S1 - LONG NGUYEN");
        }

    }
}
